package com.echo.im.common.enums;

import lombok.AllArgsConstructor;

import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;


/**
 * 0-9: 真正的消息，需要存储到数据库
 * 10-19: 状态类消息: 撤回、已读、回执
 * 20-29: 提示类消息: 在会话中间显示的提示
 * 30-39: UI交互类消息: 显示加载状态等
 * 40-49: 操作交互类消息: 语音通话、视频通话消息等
 * 50-60: 后台操作类消息: 用户封禁、群组封禁等
 * 100-199: 单人语音通话rtc信令
 * 200-299: 多人语音通话rtc信令
 *
 * @author echo
 */
@AllArgsConstructor
public enum MessageType {

    //1开头: 真正的消息，需要存储到数据库
    TEXT(101, "文字消息"),
    IMAGE(102, "图片消息"),
    FILE(103, "文件消息"),
    AUDIO(104, "语音消息"),
    VIDEO(105, "视频消息"),
    RECALL(106, "撤回"),
    READED(107, "已读"),
    TIP_TEXT(108,"文字提示"),

    //2开头:Status 状态类消息
    ONLINE(201,"用户上线"),
    OFFLINE(202,"用户下线"),

    //3开头:匿名消息
    APPLY_ADD_FRIEND(301,"申请添加好友"),
    AGREE_FRIEND_APPLY(302,"同意好友申请"),
    REFUSE_FRIEND_APPLY(303,"拒绝好友申请"),

    //4开头:ACK类
    ACK(401,"对xxx消息的确认"),

    //5开头 交互类消息
    RECEIPT(501, "消息已读回执"),
    INVITE_INTO_GROUP(502,"邀请加入群聊"),
    DEL_FRIEND(503,"删除好友");

    // getStartByInt 方法
    public static Set<Integer> getStartByInt(int start) {
        Set<Integer> result = new HashSet<>();
        for (MessageType type : EnumSet.allOf(MessageType.class)) {
            if (String.valueOf(type.code()).startsWith(String.valueOf(start))) {
                result.add(type.code());
            }
        }
        return result;
    }
//

//    LOADING(30,"加载中标记"),
//TIP_TIME(20,"时间提示"),
//
//    ACT_RT_VOICE(40,"语音通话"),
//    ACT_RT_VIDEO(41,"视频通话"),
//    USER_BANNED(50,"用户封禁"),
//    GROUP_BANNED(51,"群聊封禁"),
//    GROUP_UNBAN(52,"群聊解封"),
//    RTC_CALL_VOICE(100, "语音呼叫"),
//    RTC_CALL_VIDEO(101, "视频呼叫"),
//    RTC_ACCEPT(102, "接受"),
//    RTC_REJECT(103, "拒绝"),
//    RTC_CANCEL(104, "取消呼叫"),
//    RTC_FAILED(105, "呼叫失败"),
//    RTC_HANDUP(106, "挂断"),
//    RTC_CANDIDATE(107, "同步candidate"),
//    RTC_GROUP_SETUP(200,"发起群视频通话"),
//    RTC_GROUP_ACCEPT(201,"接受通话呼叫"),
//    RTC_GROUP_REJECT(202,"拒绝通话呼叫"),
//    RTC_GROUP_FAILED(203,"拒绝通话呼叫"),
//    RTC_GROUP_CANCEL(204,"取消通话呼叫"),
//    RTC_GROUP_QUIT(205,"退出通话"),
//    RTC_GROUP_INVITE(206,"邀请进入通话"),
//    RTC_GROUP_JOIN(207,"主动进入通话"),
//    RTC_GROUP_OFFER(208,"推送offer信息"),
//    RTC_GROUP_ANSWER(209,"推送answer信息"),
//    RTC_GROUP_CANDIDATE(210,"同步candidate"),
//    RTC_GROUP_DEVICE(211,"设备操作");


    private final Integer code;

    private final String desc;


    public Integer code() {
        return this.code;
    }
}
